B

Perl Scripts

You can run a Perl script as a prefix file with CodeWarrior projects. To enable this functionality, you must first install additional software plug-ins. After you install these plug-ins, you can configure CodeWarrior to recognize the Perl script.

This chapter discusses the following topics:


Installing the Perl Software Plug-ins

The CodeWarrior IDE uses various software plug-ins to extend its functionality. Recognizing and implementing Perl scripts in the IDE requires various Perl plug-ins. The specific plug-ins depend on the host platform you are using. The following instructions describe how to properly install the Perl plug-ins for your particular host.


Windows

CodeWarrior implements Perl script functionality with the MWPerl.dll plug-in, the PerlDLL.dll plug-in, and the MWPerl Panel.dll plug-in. You must install all three of these plug-ins for the Perl scripts to work properly.

Place the MWPerl.dll and PerlDLL.dll plug-ins in the Compiler folder. This folder resides at the following location:


\Program Files\Metrowerks\CodeWarrior\Bin\Plugins\Compiler\


Place the MWPerl Panel.dll plug-in in the Preference Panel folder. This folder resides at the following location:


\Program Files\Metrowerks\CodeWarrior\Bin\Plugins\Preference Panel



Mac OS

CodeWarrior implements Perl script functionality with the MW Perl plug-in, the Perl Panel plug-in, and the Perl extension. You must install all three of these components for the Perl scripts to work properly.

Place the MW Perl plug-in in the Compilers folder. This folder resides at the following location:


Metrowerks CodeWarrior:CodeWarrior Plugins:Compilers


Place the Perl Panel inside the Preference Panels folder. This folder resides at the following location:


Metrowerks CodeWarrior:CodeWarrior Plugins:Preference Panels


Finally, place the Perl extension inside the Extensions folder of the System Folder.


Configuring the Perl Target Settings Panel

After you install the software plug-ins, CodeWarrior allows you to specify a Perl script as a prefix file for your project. You use the Perl target settings panel to specify the Perl script. CodeWarrior treats this script as an implicit require file. The require directive is the Perl equivalent of the #include directive in C/C++.

To display the Perl settings panel, choose the Target Settings command from the Edit menu. The actual name of this command depends on your currently selected build target. The Target Settings window in Figure B.1 displays.

Figure B.1 Perl Target Settings Panel


Scroll through the list on the left side of the Target Settings window and highlight the Perl item. The Perl settings panel displays on the right side of the Target Settings window, as shown in Figure B.1.

To include a Perl script as a prefix file in the current project, type the file name for the Perl script in the Implicit require file text field. CodeWarrior treats this file as an implicit Perl require file when you build the project.


NOTE

The Perl plug-in for CodeWarrior uses the find-and-load functionality of the IDE. This functionality depends on the ability of the IDE to find referenced files using absolute paths. You must specify the access paths for any files in the Perl script or the implicit require file that are not referenced via absolute paths. You specify this path information in the Access Paths settings panel. For more information, see "Access Paths" on page 323

Perl Scripting

The Perl script implementation takes advantage of the IDE's plug-in application programming interface (API).

Listing B.1 shows a sample Perl script:

Listing B.1 Perl Script Example


# Simple Perl Example

# Print a line of text
print "Hello World!\n";

$scale0 = 0;
$scale1 = 1;
$scale2 = 2.5;

# Create and open a file for output
open (theFile, ">output.txt");

# Dump some text into the file
print theFile "The file should now be open\n";
print theFile "Let's try a few things:\n\n";

# Arithmetic
print theFile "**Arithmetic \n";
print theFile $scale1 + $scale2 . "\n";
print theFile $scale1 * $scale2 . "\n";
print theFile $scale1 % $scale2 . "\n\n";

# Boolean logic
print theFile "**Boolean \n";
print theFile ($scale0 && $scale0) . "\n";
print theFile ($scale0 && $scale1) . "\n";
print theFile ($scale1 && $scale1) . "\n";

print theFile ($scale0 || $scale0) . "\n";
print theFile ($scale0 || $scale1) . "\n";

print theFile (!$scale0) . "\n\n";

# Comparison
print theFile "**Comparisons \n";
print theFile ($scale2 == $scale2) . "\n";

print "That's it, closing file\n";

# Close the file
close theFile;


Special Considerations

When using CodeWarrior to recognize and implement Perl scripts in your project, you must keep in mind some special considerations. These considerations include:


StdIn Usage

StdIn is not supported in the prefix file. This means that the Perl script cannot accept keyboard input.


Avoiding Link Errors

The CodeWarrior linker treats the Perl script as a prefix file. Therefore, the linker expects to apply that prefix file to some source code in your project. If your project does not contain source code, the linker will display the following error message when you compile the project:


  Link Error: 'main' is undefined.

Compiling the project successfully runs the script but also produces the linker error. To avoid this error message, either ensure that your project contains some source code or set the Linker option to None in the Target Settings preference panel. For more information, see "Target Settings" on page 321.





Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: support@metrowerks.com
Copyright © 1999, Metrowerks Corp. All rights reserved.

Last updated: May 24, 1999 * Chris Magnuson * John Roseborough